package com.superwein.alibaba.dubbo.consumer.controller;

import com.superwein.alibaba.dubbo.api.service.HelloService;
import com.superwein.alibaba.dubbo.consumer.service.DegradeExceptionHandleService;
import com.superwein.alibaba.dubbo.consumer.service.LimitExceptionHandleService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class HelloController {

    @Reference(version = "1.0.0", check = false)
    private HelloService helloService;
    @Autowired
    private LimitExceptionHandleService limitExceptionHandleService;
    @Autowired
    private DegradeExceptionHandleService degradeExceptionHandleService;

    @GetMapping("/hello")
    public String test(String name) {
        return helloService.sayHello(name);
    }

    /**
     * 测试限流
     *
     * @return
     */
    @GetMapping("/hello1")
    public String hello1() {
        return limitExceptionHandleService.doSomeThing("hello1 " + new Date());
    }

    /**
     * 测试降级
     *
     * @return
     */
    @GetMapping("/hello2")
    public String hello2() {
        return degradeExceptionHandleService.doSomeThing("hello2 " + new Date());
    }

}
